package fojta;

public class ResistorMatrix extends ResistorPoint {
	private ResistorPoint matrix[][];
	private int dimension = 0;
	
	public final static int DEFAULT_DIMENSION = 10;
	
	void initMatrix(int dim) {
		
		matrix    = new ResistorPoint[dim][];
		dimension = dim;
		
		for(int i=0; i< dim; i++) {
			matrix[i] = new ResistorPoint[dim];
			
			for(int j=0; j<dim; j++)
			{
				matrix[i][j] = new ResistorPoint();
				if(i>0) {
					matrix[i][j].setUp  ( matrix[i-1][j] );
				}
				if(j>0) {
					matrix[i][j].setLeft( matrix[i][j-1] );
				}
			}
		}
		
	}
	
	ResistorMatrix() {
		initMatrix(DEFAULT_DIMENSION);
	}
	
	ResistorMatrix(int dim) {
		initMatrix(dim);
	}
	
	public ResistorPoint getPoint(int x, int y) {
		if ( x < 0 || y < 0  || 
				y >= dimension ||
				x >= dimension ) {
			return null;
		}
		return matrix[x][y];
	}
	
	public void print() {
		int dim = this.dimension;
		for(int i=0; i< dim; i++) {
			for(int j=0; j<dim; j++)
			{
				matrix[i][j].print();
				System.out.print("\t\t");
			}
			System.out.println();
		}
	}
	
}
